package com.hk.demo.player.grid;

import android.app.Activity;
import android.content.res.Configuration;
import android.view.View;

import com.hk.player.core.IPlayerControl;
import com.zhoug.common.utils.ScreenOrientationHelper;

/**
 * @author: zhoug
 * @since: 2025-08-18
 */
public class VideoControlManager {
    private IPlayerControl mControl;
    private ScreenOrientationHelper mScreenOrientationHelper;
    private Activity mActivity;
    private ScreenOrientationHelper.OnScreenOrientationListener mOnScreenOrientationListener;

    public VideoControlManager(Activity activity,IPlayerControl control) {
        this.mActivity=activity;
        this.mControl=control;
        mScreenOrientationHelper = new ScreenOrientationHelper(activity);

        mScreenOrientationHelper.setOnScreenOrientationListener(screenOrientation -> {
            if(screenOrientation==ScreenOrientationHelper.ORIENTATION_LANDSCAPE){
                mControl.setFullScreenBtnState(true);
            }else if(screenOrientation==ScreenOrientationHelper.ORIENTATION_PORTRAIT){
                mControl.setFullScreenBtnState(false);
            }
            if(mOnScreenOrientationListener!=null){
                mOnScreenOrientationListener.onScreenOrientationChanged(screenOrientation);
            }
        });
        bindControl();
    }

    private void bindControl(){
        mControl.setFullScreenBtnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                changeScreenOrientation();
            }
        });

    }

    public void setOnScreenOrientationListener(ScreenOrientationHelper.OnScreenOrientationListener onScreenOrientationListener) {
        this.mOnScreenOrientationListener = onScreenOrientationListener;
    }

    public void changeScreenOrientation(){
        mScreenOrientationHelper.changeScreenOrientation();
    }

    public void onConfigurationChanged(Configuration newConfig){
        mScreenOrientationHelper.onConfigurationChanged(newConfig);
    }


}
